/*******************************************************\
|* Author: Trevor Sundberg
\*******************************************************/

// Header protection
#pragma once
#ifndef SKUGO_CONNECTION_HPP
#define SKUGO_CONNECTION_HPP

// Includes
#include "SkugoTypes.hpp"

namespace Skugo
{
  // Responsible for reading data from a connection
  class IReader
  {
  public:
    // Read data from the client
    virtual bool Read(char** dataOut, sizeType* sizeOut) = 0;
  };

  // Responsible for writing data to a connection
  class IWriter
  {
  public:
    // Write data to the client
    virtual void Write(const char* dataIn, sizeType sizeIn) = 0;
  };

  // A connection represents the link between two endpoints
  class IConnection : public IReader, public IWriter
  {
  public:
    // Disconnect from the client.
    virtual void Disconnect() = 0;

    // Tells us whether this connection is still currently connected.
    virtual bool IsConnected() = 0;

    // Checks if the connection is locally connected.
    virtual bool IsLocal() = 0;
  };

  // A host is responsible for establishing connections
  class IHost : public IWriter
  {
  public:
    // Create a default implementation of the IHost interface
    static IHost* Create();

    // Start hosting a session
    virtual void StartHosting(unsigned short port) = 0;

    // Stop the hosting (so no more clients can connect), but does not stop the existing or pending connections
    virtual void StopHosting() = 0;

    // Gets the next recent connection (or returns NULL)
    virtual IConnection* PopNewConnection() = 0;


    // Write data to all the clients
    virtual void Write(const char* dataIn, sizeType sizeIn) = 0;

    // Close all the connections (including active and pending), but does not stop listening for new connections
    virtual void CloseAllConnections() = 0;

    // Stops hosting entirely, and closes all active or pending connections
    virtual void Shutdown() = 0;
  };
}

// End header protection
#endif
